package com.example.john.adapterdemo;

import android.app.ListActivity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import java.util.ArrayList;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class MainActivity extends ListActivity {
    private List<Map<String,Object>> data=new ArrayList<Map<String, Object>>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_main);
        //数据的初始化
        Map<String,Object> item1=new HashMap<String,Object>();
        item1.put("title","The First Title");
        item1.put("content", "This is First Content!");
        item1.put("snapshot", R.drawable.a1);

        Map<String,Object> item2=new HashMap<String,Object>();
        item2.put("title","The Second Title");
        item2.put("content","This is Second Content!");
        item2.put("snapshot",R.drawable.a2);

        Map<String,Object> item3=new HashMap<String,Object>();
        item3.put("title", "The Third Title");
        item3.put("content", "This is Third Content!");
        item3.put("snapshot", R.drawable.a3);

        data.add(item1);data.add(item2);data.add(item3);


        SimpleAdapter adapter=new SimpleAdapter(this,data,R.layout.news1_layout,
                new String[]{"snapshot","title","content"},new int[]{R.id.snapshot,R.id.titel,R.id.content}
                );
        setListAdapter(adapter);

    }

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        Log.i("john",position+"............"+id);
    }
}
